from p4a.subtyper.interfaces import ISubtyper
from zope import component

def initializeCoP(context,event):
    aggregator = context.invokeFactory('Folder',
                                       id='planet',
                                       title="Planet Aggregator")

    initializeAggregator(getattr(context,aggregator),event)

    discussionarea = context.invokeFactory('DiscussionArea',
                                           id='discussionarea',
                                           title="Discussion Area")

    initializeDiscussionArea(getattr(context,discussionarea),event)

    collabarea = context.invokeFactory('CollaborationArea',
                                       id='collabarea',
                                       title="Collaboration Area")

    initializeCollabArea(getattr(context,collabarea),event)

    sharingarea = context.invokeFactory('ContentSharingArea',
                                       id='sharingarea',
                                       title="Content Sharing Area")


    initializeSharingArea(getattr(context,sharingarea),event)

    newsevents = context.invokeFactory('Large Plone Folder',
                                       id='news_events',
                                       title="News and Events")

    initializeNewsEvents(getattr(context,newsevents),event)



def initializeAggregator(context,event):
    subtyper = component.getUtility(ISubtyper)
    subtyper.change_type(context,u'feedcontainer')

def initializeDiscussionArea(context,event):
    pass
    

def initializeCollabArea(context,event):
    wikifolder = context.invokeFactory('Folder',
                                       id='wiki',
                                       title="Wiki")
    wikifolder = getattr(context,wikifolder)

    wiki = wikifolder.invokeFactory('Document',
                                       id='frontpage',
                                       title="Wiki")

    wikifolder.setDefaultPage(wiki)

def initializeSharingArea(context,event):
    helpcenter = context.invokeFactory('HelpCenter',
                                       id='articles',
                                       title="Articles Sharing")

    
   
def initializeNewsEvents(context,event):
    constrainTypesMode = 1
    context.setConstrainTypesMode(constrainTypesMode)

    locallyAllowedTypes = ['Event','News Item','Topic']
    context.setLocallyAllowedTypes(locallyAllowedTypes)
    context.setImmediatelyAddableTypes(locallyAllowedTypes)


